<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="Apache Forrest" name="Generator">
<meta name="Forrest-version" content="0.6">
<meta name="Forrest-skin-name" content="pelt">
<title>Using Hoard</title>
<link type="text/css" href="skin/basic.css" rel="stylesheet">
<link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
<link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
<link type="text/css" href="skin/profile.css" rel="stylesheet">
<script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
<link rel="shortcut icon" href="">
</head>
<body onload="init()">
<script type="text/javascript">ndeSetTextSize();</script>
<div id="top">
<!--+
    |header
    +-->
<div class="header">
<!--+
    |start group logo
    +-->
<div class="grouplogo">
<a href="http://www.hoard.org"><img class="logoImage" alt="Hoard" src="images/hoard-logo.jpg" title="The Hoard Multiprocessor Memory Allocator"></a>
</div>
<!--+
    |end group logo
    +-->
<!--+
    |start Project Logo
    +-->
<div class="projectlogoA1">
<a href=""></a>
</div>
<!--+
    |end Project Logo
    +-->
<!--+
    |start Tabs
    +-->
<ul id="tabs"></ul>
<!--+
    |end Tabs
    +-->
</div>
</div>
<div id="main">
<div id="publishedStrip">
<!--+
    |start Subtabs
    +-->
<div id="level2tabs"></div>
<!--+
    |end Endtabs
    +-->
<script type="text/javascript" language="JavaScript"><!--
              document.write("Published: " + document.lastModified);
              //  --></script>
</div>
<!--+
    |breadtrail
    +-->
<div class="breadtrail">
             
             &nbsp;
           </div>
<!--+
    |start Menu, mainarea
    +-->
<!--+
    |start Menu
    +-->
<div id="menu">
<div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Table of Contents</div>
<div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
<div class="menuitem">
<a title="Welcome to Hoard" href="index.html">Home</a>
</div>
<div class="menuitem">
<a title="Download Hoard" href="download.html">Download</a>
</div>
<div class="menuitem">
<a title="Screenshots" href="screenshot.html">Screenshots</a>
</div>
<div class="menupage">
<div class="menupagetitle">Using Hoard</div>
</div>
<div class="menuitem">
<a title="How to Build Hoard" href="building.html">Building Hoard</a>
</div>
<div class="menuitem">
<a title="FAQs" href="faqs.html">FAQs</a>
</div>
<div class="menuitem">
<a title="License Info" href="licensing.html">Licensing Info</a>
</div>
</div>
<div id="credit"></div>
<div id="roundbottom">
<img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
<!--+
  |alternative credits
  +-->
</div>
<!--+
    |end Menu
    +-->
<!--+
    |start content
    +-->
<div id="content">
<div id="skinconf-txtlink"></div>
<h1>Using Hoard</h1>
<div id="minitoc-area">
<ul class="minitoc">
<li>
<a href="#UNIX">UNIX</a>
<ul class="minitoc">
<li>
<a href="#Linux">Linux</a>
</li>
<li>
<a href="#Solaris">Solaris</a>
</li>
</ul>
</li>
<li>
<a href="#Windows">Windows</a>
</li>
</ul>
</div>


<p>
Using Hoard is easy. On UNIX-based platforms, all you have to do is set one environment variable. You do not need to change any source code, recompile or relink your application. On Windows, you actually have even greater flexibility.
</p>



<a name="N1000F"></a><a name="UNIX"></a>
<h2 class="boxed">UNIX</h2>
<div class="section">
<p>
In UNIX, you can use the LD_PRELOAD variable to use
Hoard instead of the system allocator for any program not linked with
the "static option" (that's most programs). Below are settings for
Linux and Solaris.
  </p>
<a name="N10018"></a><a name="Linux"></a>
<h3 class="boxed">Linux</h3>
<pre class="code">
LD_PRELOAD="/path/libhoard.so"
    </pre>
<a name="N10023"></a><a name="Solaris"></a>
<h3 class="boxed">Solaris</h3>
<p>
    Depending on whether you are using the GNU-compiled version (as
    produced by compile) or the Sun
    Workshop-compiled versions (produced by
    compile-sunw), your settings will be slightly
    different.
    </p>
<table class="ForrestTable" cellspacing="1" cellpadding="4">
        
<tr>
              
<td colspan="1" rowspan="1">Version</td>
              <td colspan="1" rowspan="1">Setting</td>
        
</tr>
        
<tr>
              
<td colspan="1" rowspan="1">GNU</td>
              <td colspan="1" rowspan="1">
                
<pre class="code">
LD_PRELOAD="/path/libhoard.so"
                </pre>
              
</td>
           
</tr>
           
<tr>
              
<td colspan="1" rowspan="1">Sun (<em>32-bits</em>)</td>
              <td colspan="1" rowspan="1">
                 
<pre class="code">
LD_PRELOAD="/path/libhoard_32.so:/usr/lib/libCrun.so.1"
                  </pre>
              
</td>
           
</tr>
           
<tr>
              
<td colspan="1" rowspan="1">Sun (<em>64-bits</em>)</td>
              <td colspan="1" rowspan="1">
                 
<pre class="code">
LD_PRELOAD="/path/libhoard_64.so:/usr/lib/64/libCrun.so.1"
                  </pre>
              
</td>
           
</tr>
     
</table>
<p>
For some security-sensitive applications, Solaris requires you place
libraries used in LD_PRELOAD into the /usr/lib/secure directory. In that event,
after copying these libraries into /usr/lib/secure, set
LD_PRELOAD by omitting the absolute locations of the libraries, as follows:
       </p>
<pre class="code">
LD_PRELOAD="libhoard.so:libCrun.so.1"
       </pre>
</div>


<a name="N1007E"></a><a name="Windows"></a>
<h2 class="boxed">Windows</h2>
<div class="section">
<p>
  There are two ways to use Hoard on Windows.
  </p>
<ol>
  
<li>
    Using winhoard
    <p>
The first and best method is to use winhoard. Winhoard replaces
malloc/new calls from your program and any DLLs it might use (leaving
HeapAlloc calls intact).
</p>


<p>
To use the Winhoard version, link your executable with
usewinhoard.obj and
winhoard.lib, and then use
winhoard.dll:
</p>


<pre class="code">
cl /Ox /MD myprogram.cpp usewinhoard.obj winhoard.lib
</pre>

  
</li>
  
<li>
    Using libhoard
    <p>

The other method is to link directly with the libhoard DLL. This
approach is simple, but only suitable for small applications, since it
will not affect malloc calls in any other DLL you might load. To use
this option, you should put the following into your source code as the
very first lines:
</p>


<pre class="code">
#if defined(USE_HOARD)
#pragma comment(lib, "libhoard.lib") 
#endif 
</pre>


<p>
This stanza should be in the first part of a header file included by
all of your code. It ensures that Hoard loads before any other library
(you will need libhoard.lib in your path). When
you execute your program, as long as libhoard.dll
is in your path, your program will run with Hoard instead of the
system allocator. Note that you must compile your program with the
/MD flag, as in:
</p>


<pre class="code">
cl /MD /G6 /Ox /DUSE_HOARD=1 myprogram.cpp 
</pre>


<p>
Hoard will not work if you use another switch (like
/MT) to compile your program.
    </p>
  
</li>
  
</ol>
</div>




</div>
<!--+
    |end content
    +-->
<div class="clearboth">&nbsp;</div>
</div>
<div id="footer">
<!--+
    |start bottomstrip
    +-->
<div class="lastmodified">
<script type="text/javascript"><!--
document.write("Last Published: " + document.lastModified);
//  --></script>
</div>
<div class="copyright">
 Copyright &copy; 2005 Emery Berger.</div>
<div id="feedback">
    Send feedback about the website to:
  <a id="feedbackto" href="mailto:emery@cs.umass.edu?subject=Feedback,using.html">emery@cs.umass.edu</a>
</div>
<!--+
    |end bottomstrip
    +-->
</div>
</body>
</html>
